2000W / 48V LLC Battery-Charger  V1.00
xmc_acmp.c
Go to the documentation of this file.
1 
63 /*********************************************************************************************************************
64  * HEADER FILES
65  ********************************************************************************************************************/
66 #include <xmc_acmp.h>
67 
68 /* If ACMP is available*/
69 #if defined (COMPARATOR)
70 
71 /*********************************************************************************************************************
72  * MACROS
73  ********************************************************************************************************************/
74 
75 #define XMC_ACMP_INSTANCE_1 (1U) /* Instance number for Slice-1 */
76 
77 /*********************************************************************************************************************
78  * API IMPLEMENTATION
79  ********************************************************************************************************************/
80 
81 /* API to initialize an instance of ACMP module */
82 void XMC_ACMP_Init(XMC_ACMP_t *const peripheral, uint32_t instance, const XMC_ACMP_CONFIG_t *const config)
83 {
84 
85  XMC_ASSERT("XMC_ACMP_Init:NULL Configuration", (config != (XMC_ACMP_CONFIG_t *)NULL))
86  XMC_ASSERT("XMC_ACMP_Init:Wrong module pointer", XMC_ACMP_CHECK_MODULE_PTR(peripheral))
87  XMC_ASSERT("XMC_ACMP_Init:Wrong instance number", XMC_ACMP_CHECK_INSTANCE(instance) )
88 
89  /*
90  * Initializes the comparator with configuration supplied. Low power node setting is retained during initialization.
91  * All the instances passed are handled with low power setting, to avoid conditional check for ACMP0 instance.
92  * This reduces the code size. No side effects, because this register bit field is empty for other instances.
93  */
94  peripheral->ANACMP[instance] = ((peripheral->ANACMP[instance] & (uint32_t)COMPARATOR_ANACMP0_CMP_LPWR_Msk)) |
95  (uint32_t)config->anacmp;
96 }
97 
98 /* API to select INP source */
99 void XMC_ACMP_SetInput(XMC_ACMP_t *const peripheral, uint32_t instance, XMC_ACMP_INP_SOURCE_t source)
100 {
101  XMC_ASSERT("XMC_ACMP_SetInput:Wrong module pointer", XMC_ACMP_CHECK_MODULE_PTR(peripheral))
102  XMC_ASSERT("XMC_ACMP_SetInput:Wrong instance number", ((instance != XMC_ACMP_INSTANCE_1) &&
103  XMC_ACMP_CHECK_INSTANCE(instance)) )
104  XMC_ASSERT("XMC_ACMP_SetInput:Wrong input source", ((source == XMC_ACMP_INP_SOURCE_STANDARD_PORT) ||
105  (source == XMC_ACMP_INP_SOURCE_ACMP1_INP_PORT)) )
106 
107  /*
108  * Three options of Input Setting are listed below
109  * 1. The comparator inputs aren't connected to other comparator inputs
110  * 2. Can program the comparators to connect ACMP0.INP to ACMP1.INP in XMC1200 AA or XMC1300 AA
111  * Can program the comparators to connect ACMP0.INN to ACMP1.INP in XMC1200 AB or XMC1300 AB or XMC1400 AA
112  * 3. Can program the comparators to connect ACMP2.INP to ACMP1.INP
113  * 4. Can program the comparators to connect ACMP3.INP to ACMP1.INP in XMC1400
114  */
115  peripheral->ANACMP[instance] = ((peripheral->ANACMP[instance] & (uint32_t)(~COMPARATOR_ANACMP0_ACMP0_SEL_Msk))) |
116  (uint32_t)source;
117 }
118 
119 #endif /* #ifdef ACMP_AVAILABLE */
#define COMPARATOR_ANACMP0_CMP_LPWR_Msk
Definition: XMC1400.h:4686
#define XMC_ASSERT(msg, exp)
Definition: xmc_common.h:132
#define COMPARATOR_ANACMP0_ACMP0_SEL_Msk
Definition: XMC1400.h:4684